package xyz.ddlnt.serviceusr.controller;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.dto.PageDTO;
import xyz.ddlnt.model.dto.PostDescriptionDTO;
import xyz.ddlnt.model.dto.SearchDTO;
import xyz.ddlnt.model.entity.Post;
import xyz.ddlnt.model.vo.PostLatestVO;
import xyz.ddlnt.model.vo.PostNodeVO;
import xyz.ddlnt.model.vo.PostVO;
import xyz.ddlnt.serviceusr.service.PostService;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/9 16:51
 */
@Slf4j
@RequestMapping("/post")
@RestController
@RequiredArgsConstructor
public class PostController {

    @Resource
    private PostService postService;

    /**
     * 发布帖子
     * @param postDescriptionDTO
     * @return
     */
    @PostMapping("/PublishPost")
    public Result<Boolean> PublishPost(@RequestBody PostDescriptionDTO postDescriptionDTO) {
        return Result.success(postService.PublishPost(postDescriptionDTO));
    }

    /**
     * 查询帖子列表
     * @return
     */
//    @Cacheable(value = "getPostLists", key = "#pageDTO.pageNum")
    @PostMapping("/getPostLists")
    public Result<List<PostVO>> getPostLists(@RequestBody PageDTO pageDTO) {
        return Result.success(postService.getPostLists(pageDTO));
    }

    /**
     * 搜索帖子
     * @param searchDTO
     * @return
     */
    @PostMapping("/searchPost")
    public Result<List<PostVO>> searchPostList(@RequestBody SearchDTO searchDTO) {
        return Result.success(postService.searchPostList(searchDTO));
    }

    /**
     * 获取帖子信息
     * @param id
     * @return
     */
    @GetMapping("/getPost")
    public Result<PostVO> getPost(@RequestParam Long id) {
        return Result.success(postService.getPost(id));
    }

    /**
     * 查询博主最新发布列表
     * @return
     */
    @PostMapping("/getBloggerPublish")
    public Result<List<PostVO>> getBloggerPublish(@RequestBody PageDTO pageDTO) {
        return Result.success(postService.getBloggerPublish(pageDTO));
    }

    /**
     * 查询博主最新发布列表
     * @param bloggerId
     * @return
     */
    @GetMapping("/getPostLatestList")
    public Result<List<PostLatestVO>> getPostLatestList(@RequestParam Long bloggerId) {
        return Result.success(postService.getPostLatestList(bloggerId));
    }

    /**
     * 查询帖子目录和节点信息
     * @param postId
     * @return
     */
    @GetMapping("/getPostNodeInfo")
    public Result<PostNodeVO> getPostNodeInfo(@RequestParam Long postId) {
        return Result.success(postService.getPostNodeInfo(postId));
    }

}
